home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / as2db1 / blk_del.bas < prev    next >
BASIC Source File  |  1994-01-01  |  8KB  |  252 lines

  1. Option Explicit
  2.  
  3.     ' customize this for the job:
  4.     '----------------------------
  5.  
  6. ' the raw ascii input file:
  7. Global Const gcDefInputName = "c:\vb\asc2mdb\specif\blk_del.rpt"
  8.  
  9. ' the .mdb destination:
  10. Global Const gcDefDbName = "c:\vb\asc2mdb\blk_del.mdb"
  11.  
  12. ' error log: make sure this directory exists!
  13. Global Const gcErrFileName = "c:\vb\asc2mdb\blk_derr.LOG"
  14.  
  15. ' name of the table in the above .mdb file:
  16. Global Const gcTable = "hifinance"
  17.  
  18. ' length of the record when PassFilter is thru with it:
  19. Global Const RecordLen = 54
  20.  
  21. Function Mode345Key ()
  22.     
  23.     'change this to return the array item number
  24.     ' (in gIOFld) of the Field you want to use for
  25.     ' these Replace Modes.
  26.     ' Field needs unique Index for mode 4/5
  27.     '  since they use the Seek method.
  28.     ' 3>  (block delete from existing database)
  29.     ' 4>  (record by record seek/update; else add)
  30.     ' 5>  (recurd by record seek/update; else error)
  31.  
  32.     'Mode345Key = 1
  33.      Error 33000 'shouldn't be called in this app
  34. End Function
  35.  
  36. Function Mode45Index ()
  37.     
  38.     'change this to return the Name of the Index
  39.     ' to use for a Replace Mode 4 or 5 update
  40.     
  41.     ' Field needs unique Index for mode 4/5
  42.     '  since they use the Seek method.
  43.     ' 4>  (record by record seek/update; else add)
  44.     ' 5>  (recurd by record seek/update; else error)
  45.     
  46.     'Mode45Index = "xxx"
  47.     Error 33000  'shouldn't be called in this app
  48.  
  49. End Function
  50.  
  51. Function PassFilter (InFileLine)
  52.     Dim Msg As String
  53.     'change this to filter out records you DON'T
  54.     ' want to pass to your database from the ASCII file
  55.     
  56.     'This Function is called by the subroutine
  57.     '   "cmdTranslate_Click" in GENERAL.FRM
  58.     'Just before it posts each line to the database,
  59.     '   it passes the line to this function (PassFilter).
  60.     
  61.     'If TRUE is returned, it posts; otherwise, not posted;
  62.     '  so set PassFilter = False for each InFileLine
  63.     '  (record) you want to reject
  64.     
  65.     'This Function also gives you a chance to change
  66.     ' InFileLine before processing it.
  67.     '  NOTE: When you return TRUE (meaning "post this
  68.     '  record", the InFileLine MUST be the specified
  69.     '  length, with the fields positioned consistent
  70.     '  with the gIOFields array)
  71.  
  72.     'When reformatting COBOL type report files into
  73.     ' ASCII field oriented records:
  74.  
  75.     '* define a type in the declarations
  76.     '  section of this module (SPECIFIC.BAS) that defines
  77.     '  the layout of the ASCII record.  This layout
  78.     '  should correspond to gIOFlds array.
  79.     '* Then declare an instance of the type in this
  80.     '  Function, using Static not Dim
  81.     '* build up each record in the Static, returning
  82.     '  True each time it holds a record to post.
  83.  
  84.     '---------------------------------------------
  85.  
  86.     On Error GoTo PassFilterError
  87.  
  88.     ' default will be "true"
  89.     
  90.     Static WorkLine As String * 54
  91.  
  92.     PassFilter = False
  93.  
  94.     Select Case True
  95.     
  96.     Case InFileLine Like "FISCAL PERIOD: *"
  97.         Mid$(WorkLine, 1, 2) = Mid$(InFileLine, 16, 2)  'Fiscal_Month (yr)
  98.         Mid$(WorkLine, 3, 2) = Mid$(InFileLine, 19, 2)  'Fiscal_Month (mo)
  99.     Case InFileLine Like "SOP ACCOUNT: *"
  100.         Mid$(WorkLine, 5, 2) = Mid$(InFileLine, 18, 2)  'SOP_Line
  101.         Mid$(WorkLine, 7, 3) = Mid$(InFileLine, 21, 3)  'LSC
  102.     Case InFileLine Like "                     001*"
  103.         Mid$(WorkLine, 10, 3) = Mid$(InFileLine, 27, 3)  'GL_Base
  104.         Mid$(WorkLine, 13, 8) = Mid$(InFileLine, 32, 8) 'GL_Account
  105.         Mid$(WorkLine, 21, 3) = Mid$(InFileLine, 42, 3) 'GL_LSC
  106.         Mid$(WorkLine, 24, 9) = Mid$(InFileLine, 47, 9) 'GL_Alloc
  107.         Mid$(WorkLine, 33, 22) = SvcCurrStrip(Mid$(InFileLine, 57, 22)) 'GL_Amount_US
  108.         'each time we get here, we have a line to post
  109.         InFileLine = WorkLine
  110.         PassFilter = True
  111.     End Select
  112.     
  113.     Exit Function
  114.  
  115. PassFilterError:
  116.  
  117.     Msg = Err & " " & Error & NL
  118.     Msg = Msg & " builing the PassFilter, check recordlength?"
  119.     MsgBox Msg
  120.     End
  121.  
  122.  
  123. End Function
  124.  
  125. Private Sub SetupIndexes ()
  126.     
  127.     ' called by SetupSpecifics in this module
  128.     ' customize this for the indexes you want
  129.     ' the array should be the size n = number of
  130.     ' indexes, and each of the n indexes must
  131.     ' be specified
  132.     '----------------------------------------
  133.     
  134.     ReDim gIndexPtrn(3)
  135.     
  136.     gIndexPtrn(1).Name = "Fiscal_Month"
  137.     gIndexPtrn(1).Fields = "Fiscal_Month"
  138.     gIndexPtrn(1).Primary = False
  139.     gIndexPtrn(1).Unique = False
  140.     
  141.     gIndexPtrn(2).Name = "SOP_Line"
  142.     gIndexPtrn(2).Fields = "SOP_Line"
  143.     gIndexPtrn(2).Primary = False
  144.     gIndexPtrn(2).Unique = False
  145.     
  146.     gIndexPtrn(3).Name = "GL_Base"
  147.     gIndexPtrn(3).Fields = "GL_Base"
  148.     gIndexPtrn(3).Primary = False
  149.     gIndexPtrn(3).Unique = False
  150.     
  151. End Sub
  152.  
  153. Private Sub SetupIOFields ()
  154.     
  155.     ' Called by SetupSpecifics in this module to
  156.     ' initialize gIOFld array.
  157.     ' Customize this for the fields in database.
  158.     ' gIOFld array is used by the cmdTranslate_Click
  159.     ' method of GENERAL.FRM to load the database.
  160.  
  161.     ' InStart and InLength:
  162.  
  163.     'a) In the case of record formatted ASCII files:
  164.     '  the inStart and inLength fields tell how
  165.     '  to parse the INPUT FILE, and create the field
  166.     '  contents.
  167.     
  168.     'b) In the case of report formatted ASCII files
  169.     '  (like COBOL report files):
  170.     '  the inStart and inLength fields tell how
  171.     '  to parse the ARGUMENT returned from the
  172.     '  PassFilter method in SPECIFIC.BAS.  (Assuming
  173.     '  your PassFilter Sub reformats the report lines
  174.     '  into records -- see comments in that sub)
  175.     
  176.     ' The array should be the size n = number of
  177.     ' fields, and each of the n fields must
  178.     ' be specified
  179.     '------------------------------------------
  180.  
  181.     ReDim gIOFld(8)
  182.     
  183.     gIOFld(1).dbName = "Fiscal_Month"    'name for database
  184.     gIOFld(1).dbSize = 4           'size for database
  185.     gIOFld(1).dbType = DB_TEXT     'type for database
  186.     gIOFld(1).inStart = 1          'for parsing input
  187.     gIOFld(1).inLength = 4         'for parsing input
  188.     
  189.     gIOFld(2).dbName = "SOP_Line"
  190.     gIOFld(2).dbSize = 2
  191.     gIOFld(2).dbType = DB_TEXT
  192.     gIOFld(2).inStart = 5
  193.     gIOFld(2).inLength = 2
  194.     
  195.     gIOFld(3).dbName = "LSC"
  196.     gIOFld(3).dbSize = 3
  197.     gIOFld(3).dbType = DB_TEXT
  198.     gIOFld(3).inStart = 7
  199.     gIOFld(3).inLength = 3
  200.  
  201.     gIOFld(4).dbName = "GL_Base"
  202.     gIOFld(4).dbSize = 3
  203.     gIOFld(4).dbType = DB_TEXT
  204.     gIOFld(4).inStart = 10
  205.     gIOFld(4).inLength = 3
  206.  
  207.     gIOFld(5).dbName = "GL_Account"
  208.     gIOFld(5).dbSize = 8
  209.     gIOFld(5).dbType = DB_TEXT
  210.     gIOFld(5).inStart = 13
  211.     gIOFld(5).inLength = 8
  212.  
  213.     gIOFld(6).dbName = "GL_LSC"
  214.     gIOFld(6).dbSize = 3
  215.     gIOFld(6).dbType = DB_TEXT
  216.     gIOFld(6).inStart = 21
  217.     gIOFld(6).inLength = 3
  218.  
  219.     gIOFld(7).dbName = "GL_Alloc"
  220.     gIOFld(7).dbSize = 9
  221.     gIOFld(7).dbType = DB_TEXT
  222.     gIOFld(7).inStart = 24
  223.     gIOFld(7).inLength = 9
  224.  
  225.     gIOFld(8).dbName = "GL_Amount_US"
  226.     gIOFld(8).dbSize = 8
  227.     gIOFld(8).dbType = DB_CURRENCY
  228.     gIOFld(8).inStart = 33
  229.     gIOFld(8).inLength = 22
  230.  
  231. End Sub
  232.  
  233. Sub SetupSpecifics ()
  234.     
  235.     ' customize this for the job:
  236.     '----------------------------
  237.  
  238.     App.Title = "Report Muncher"
  239.     ReplaceMode = 0      'see readme
  240.  
  241.     'shouldn't need customizing:
  242.     '---------------------------
  243.  
  244.     NL = Chr(13) & Chr(10)
  245.     
  246.     SetupIOFields
  247.     SetupIndexes
  248.     
  249.  
  250. End Sub
  251.  
  252.